package org.bangumibuddy.controller;

import org.bangumibuddy.pojo.DownloadInfo;
import org.bangumibuddy.pojo.ResponseResult;
import org.bangumibuddy.pojo.RssDownloadInfo;
import org.bangumibuddy.service.DownloadService;
import org.bangumibuddy.service.RssService;
import org.bangumibuddy.service.TorrentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/download")
public class DownloadController {

    @Autowired
    RssService rssService;

    @Autowired
    DownloadService downloadService;

    @GetMapping("/info/{animeId}")
    public ResponseResult<List<RssDownloadInfo>> getAnimeDownloadInfo(@PathVariable Long animeId) {
        List<RssDownloadInfo> rssDownloadInfoByAnimeId = rssService.getRssDownloadInfoByAnimeId(animeId);
        return ResponseResult.success(rssDownloadInfoByAnimeId);
    }

    @PostMapping("/pause")
    public ResponseResult pauseDownload(@RequestParam String hash) {
        downloadService.pause(hash);
        return ResponseResult.success();
    }

    @PostMapping("/resume")
    public ResponseResult resumeDownload(@RequestParam String hash) {
        downloadService.resume(hash);
        return ResponseResult.success();
    }
}
